from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
          #文本
        long_text=("多元微分学:\n"
                     "通关攻略")
        text = Text(long_text,color=YELLOW,
                   font_size=200).move_to([0,0,0])
        text1 = Tex(r"\text{秘籍1:二元极限}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,10,0])
        text2 = Tex(r"\text{秘籍2:链式法则}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,-10,0])
        text3 = Tex(r"\text{秘籍3:一阶偏导}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-10,0])
        text4 = Tex(r"\text{秘籍4:二阶偏导}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,10,0])
        text5 = Tex(r"\text{重要题型:多元函数极值}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        text6 = Tex(r"\text{补充细碎知识点}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-20,0])
                              
        rectangle=Rectangle(color=GREEN,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([0, 0, 0])
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([0, 0, 0])
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle2.move_to([0, 0, 0])
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle3.move_to([0, 0, 0])
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle4.move_to([0, 0, 0])
        rectangle5=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle5.move_to([0, 0, 0])
        rectangle6=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle6.move_to([0, 0, 0])
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle7.move_to([0, 0, 0])
        self.play(Write(text),self.camera.frame.animate.scale(0.8),Create(rectangle)
                  ,Create(rectangle1),Create(rectangle2)
                  ,Create(rectangle3),Create(rectangle4)
                  ,Create(rectangle5),Create(rectangle6),Create(rectangle7))
        self.wait()
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame),ReplacementTransform(rectangle,text1)
                  ,ReplacementTransform(rectangle2,text2)
                  ,ReplacementTransform(rectangle3,text3)
                  ,ReplacementTransform(rectangle4,text4)
                  ,ReplacementTransform(rectangle5,text5)
                  ,ReplacementTransform(rectangle6,text6))
                    
        rectangle8=Rectangle(color=BLUE,fill_opacity=0.0,width=90,height=50
                            ,stroke_color=GREEN,stroke_width=20)
        rectangle8.move_to([0, 0, 0])
        self.play(Create(rectangle8))
        text7 = Tex(r"\text{仪表轮盘}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle8,UP,buff=1)
        self.play(Write(text7))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #循环
        
        self.play(rectangle7.animate().move_to([25,-10,0]))     
        self.play(self.camera.frame.animate.scale(0.5).move_to([25,-10,0]))

        self.wait()